package com.headwind.logistics.log.controller;

import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.log.Service.intl.LogServiceIntl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Author 小恶魔
 * @Date 2020-07-20 22:22
 * @Version 1.0
 * @DESCRIPTION 登录日志控制层
 */
@Controller
@RequestMapping("/admin/log")
public class LoginLogController {

    //日志业务逻辑层
    @Resource
    private LogServiceIntl logServiceIntl;

    //api响应接口
    @Resource
    private ResultGenerator resultGenerator;

    /**
     * 获取全部登录日志信息
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryLoginLog")
    @ResponseBody
    public LayuiUtil queryLoginLogPage(Integer page,Integer limit){

        return LayuiUtil.data(logServiceIntl.queryAllLoginLogPage(null,null).size()
                ,logServiceIntl.queryAllLoginLogPage(page, limit));

    }

    /**
     * 批量删除登录日志
     * @param logIdList
     * @return
     */
    @PostMapping("/batchDeleteLoginLog")
    @ResponseBody
    public RestResult batchDelete(String logIdList){

        Integer count = logServiceIntl.batchDeleteLoginLogById(logIdList);

        if (count >0){
            return resultGenerator.getSuccessResult();
        }

        return resultGenerator.getFailResult("删除失败，重新试试看");

    }

}
